﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace SQL_Manager
{
    public enum DriverType
    {
        MYSQL = 0,
        PGSQL = 1,
        SQLITE = 2
    }

    abstract public class Database
    {
        static public Database instance = null;

        //
        // Returns the already-constructed object so we don't need to keep re-creating Database
        // You can find examples on how to use this in the Account & Player class
        //
        static public void GetInstance(out Database Db)
        {
            Db = instance;
        }

        //
        //TODO: Expand the Database class
        //
        abstract public Hashtable query(string query);
        abstract public List<Hashtable> queryAll(string query);
        abstract public void query(string query, out Hashtable table);
        abstract public void queryAll(string query, out List<Hashtable> table);
        
        abstract public int execute(string query);
        abstract public bool connected();
        abstract public void close();

        //
        // Threaded operations
        //
        public void ThreadedRefQuery(string query, ref Hashtable table)
        {
            System.Threading.Thread tThread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(internalThreadedRefQuery));
            tThread.Start(new object[] { query, table });
        }

        public void internalThreadedRefQuery(object Parameters)
        {
            // I don't like doing this, but type-casting doesn't seem to work here
            object[] Ps = (object[])Parameters;

            Ps[1] = this.query((string)Ps[0]);

            // Get rid of this pest
            Ps = null;
        }
    }
}
